﻿<?php
include_once 'dbconfig.php';
if (isset ( $_POST ['userName'] )) {
	$username = $_POST ['userName'];
	$password = sha1 ( $_POST ['password'] );
	// 要求准备语句的命名参数
	$sql = "select * from user where username=:username and password=:password";
	$pdoStatment = $pdo->prepare ( $sql );
	$array = array (
			"username" => $username,
			"password" => $password 
	);
	$ret = $pdoStatment->execute ( $array );
	if ($ret) {
		$result = $pdoStatment->fetch ();
		// 如果内容不为空，查找到帐号
		if ($result) {
			// 登录成功
			session_start ();
			$_SESSION ['userLogined'] = $username;
			header ( "location:jump.php?url=index.php&error=登录成功&wait=2" );
			exit ();
		} else {
			header ( "location:jump.php?url=login.php&error=用户名或者密码错&wait=2" );
			exit ();
		}
	} else {
		header ( "location:jump.php?url=login.php&error=系统内容错！&wait=2" );
	}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>用户登录</title>
<!-- BOOTSTRAP STYLES-->
<link href="assets/css/bootstrap.css" rel="stylesheet" />
<!-- FONTAWESOME STYLES-->
<link href="assets/css/font-awesome.css" rel="stylesheet" />
<!-- CUSTOM STYLES-->
<link href="assets/css/custom.css" rel="stylesheet" />
<!-- GOOGLE FONTS-->

</head>
<body>
	<div class="container">
		<div class="row text-center ">
			<div class="col-md-12">
				<br />
				<br />
				<h2>用户登录</h2>

				<h5>( 授权访问 )</h5>
				<br />
			</div>
		</div>
		<div class="row ">

			<div
				class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1">
				<div class="panel panel-default">
					<div class="panel-heading">
						<strong> 录入详细的登录信息 </strong>
					</div>
					<div class="panel-body">
						<form role="form" action='login.php' method='post'>
							<br />
							<div class="form-group input-group">
								<span class="input-group-addon"><i class="fa fa-tag"></i></span>
								<input name='userName' type="text" class="form-control"
									placeholder="你的账号 " />
							</div>
							<div class="form-group input-group">
								<span class="input-group-addon"><i class="fa fa-lock"></i></span>
								<input name='password' type="password" class="form-control"
									placeholder="你的密码" />
							</div>
							<div class="form-group">
								<label class="checkbox-inline"> <input type="checkbox" />记住
								</label> <span class="pull-right"> <a href="#">忘记密码 ? </a>
								</span>
							</div>
							<input type='submit' CLASS="BTN BTN-PRIMARY" value='登录' />
							<hr />
							没注册 ? <a href="insertuser.php">点我 </a>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>


	<!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
	<!-- JQUERY SCRIPTS -->
	<script src="assets/js/jquery-1.10.2.js"></script>
	<!-- BOOTSTRAP SCRIPTS -->
	<script src="assets/js/bootstrap.min.js"></script>
	<!-- METISMENU SCRIPTS -->
	<script src="assets/js/jquery.metisMenu.js"></script>
	<!-- CUSTOM SCRIPTS -->
	<script src="assets/js/custom.js"></script>

</body>
</html>
